<?php
include_once ("../function.php");
include_once ("member_class.php");
include_once ("ulevel_class.php");
include_once ("system_class.php");
include_once ("email_class.php");
date_default_timezone_set("PRC");
class bonus_class {
    //见点奖
    function b2bonus3($uid,$nickname,$rep,$rel){
        $_ulevel_cl=new ulevel_class();
        $us=getMemberbyID($uid);
        $sql="select * from `member` where id in(0".$rep."0) and ".$rel."-plevel<=".$rel." ";
        if($query = mysql_query($sql)){
            while ($row=mysql_fetch_array($query)){
                $cha=$us['plevel']-$row['plevel'];
                $_iul=$_ulevel_cl->getulevelbyulevel($row['ulevel']);
                if($cha<=$_iul['yl4']){
                    $b3=$_iul['yl3'];
                    if($b3>0) {
                        $beizhu = $b3 . "管理奖";
                        edit_sql("update `member` set b3=b3+".$b3." where id=".$row['id']." ");
                        $this->bonus_laiyuan($row['id'],$row['nickname'],$uid,$nickname,3,$b3,$beizhu);
                    }
                }
            }
        }
    }
    function baodan($id){
        $us=getMemberbyID($id);
        if($us['bdid']){
            $bduser=getMemberbyID($us['bdid']);
            if($bduser['isbd']==2){
                $_ulevel_class=new ulevel_class();
                $_ul=$_ulevel_class->getulevelbyulevel($bduser['ulevel']);
                if($_ul['yl5']>0){
                    $b6 = $_ul['yl5'];
                    edit_sql("update `member` set b6=b6+".$b6." where id=".$bduser['id']." ");
                    $beizhu=$_ul['yl5']."服务费";
                    $this->bonus_laiyuan($bduser['id'],$bduser['nickname'],$us['id'],$us['nickname'],6,$b6,$beizhu);
                }
            }
        }
    }

    //见点奖
    function b2bonus0($uid,$nickname,$rep,$rel){
        $_ulevel_cl=new ulevel_class();
        $us=getMemberbyID($uid);
        $sql="select * from `bmember` where id in(0".$rep."0) and ".$rel."-plevel<=".$rel." ";
        if($query = mysql_query($sql)){
            while ($row=mysql_fetch_array($query)){
                $_iul=$_ulevel_cl->getulevelbyulevel($row['ulevel']);
                $b2=$_iul['yl14'];
                $bpd = $this->bmemberpdsx($row['id'],$b2,1);
                if($bpd[0]>0) {
                    if ($bpd[1] == 1) {
                        $beizhu = $bpd[0] . "见点奖(封顶)";
                    } else {
                        $beizhu = $bpd[0] . "见点奖";
                    }
                    edit_sql("update `member` set b4=b4+".$bpd[0].",zfmey=zfmey+{$bpd[0]} where id=".$row['userid']." ");
                    $this->bonus_laiyuan($row['userid'],$row['nickname'],$uid,$nickname,4,$bpd[0],$beizhu);
                }
            }
        }
    }
/**
 * 直推奖
 *
 * */
    function b1bouns($id){
        $us=getMemberbyID($id);
        $reid=getMemberbyID($us['reid']);
        $ulevel_cl = new ulevel_class ();
        $_iul=$ulevel_cl->getulevelbyulevel($reid['ulevel']);
        $b1=$_iul['yl1'];
        if($b1>0){
            $beizhu=$b1."销售提成";
            edit_sql("update `member` set b1=b1+".$b1." where id=".$reid['id']." ");
            $this->bonus_laiyuan($reid['id'], $reid['nickname'], $us['id'], $us['nickname'], 1, $b1, $beizhu);
        }



//         $bpd = $this->pdsx($reid['id'],$b1,1);
//        if($b2>0&&$reid['cishu']==1){
//              if($bpd[1]==1){
//                  $beizhu=$b1."直推奖(封顶)";
//              }else{
//            $beizhu=$b2."直推奖";
//               }
//            edit_sql("update `member` set b2=b2+".$b2." where id=".$reid['id']." ");
//            $this->bonus_laiyuan($reid['id'], $reid['nickname'], $us['id'], $us['nickname'], 2, $b2, $beizhu);
//        }
    }
    /**
     * 静态奖
     * */
    function b1bonus($id,$yeji,$zong){
        $sql="select ulevel,sgb,id,nickname from member where id=".$id;
        $user=getOne($sql);
        $_ulevel_cl=new ulevel_class();
        $iul=$_ulevel_cl->getulevelbyulevel($user['ulevel']);
        if($user['ulevel']==1){
            $cs=1;
        }elseif($user['ulevel']==2){
            $cs=3;
        }elseif($user['ulevel']==3){
            $cs=5;
        }
            $mey = $yeji*$iul['yl1']/100;
            $b1=round($mey*$cs/$zong,2);
            $bpd = $this->pdsx($user['id'],$b1,1);
            if ($bpd[0] > 0) {
                if($bpd[1]==1){
                    $beizhu = $bpd[0] . "静态奖(封顶)";
                }else{
                    $beizhu = $bpd[0] . "静态奖";
                }
                edit_sql("update `member` set b1=b1+" . $bpd[0] . ",zfmey=zfmey+" . $bpd[0] . ",gwb=gwb+" . $bpd[0] . " where id=" . $user['id'] . " ");
                $this->bonus_laiyuan($user['id'], $user['nickname'], $user['id'], $user['nickname'], 1, $bpd[0], $beizhu);
            }
    }
    //业绩奖
    function b4bonus($ffmey){
      //  $us=getMemberbyID($id);
        $dateymd=date("Y-m-d");
        $_ulevel_cl=new ulevel_class();
/*        $sql="select * from systemyeji where ydate like '%{$dateymd}%'";
        $sysyeji=getOne($sql);*/
        $sql1="select count(*) as c1 from member where ulevel2=1";
        $xing1=getOne($sql1);
        $sql2="select count(*) as c2 from member where ulevel2=2";
        $xing2=getOne($sql2);
        $sql3="select count(*) as c3 from member where ulevel2=3";
        $xing3=getOne($sql3);
        $sql4="select count(*) as c4 from member where ulevel2=4";
        $xing4=getOne($sql4);
        $sql5="select count(*) as c5 from member where ulevel2=5";
        $xing5=getOne($sql5);
        $sql6="select ulevel,id,nickname,ulevel2,cishu from member where ulevel2>0";
        $query=mysql_query($sql6);
            while ($row=mysql_fetch_array($query)){
                $row_iul=$_ulevel_cl->getulevelbyulevel($row['ulevel']);
                if($row['ulevel2']==1){
                    $b3=$ffmey*$row_iul['yl9']/100/$xing1['c1'];
                }elseif($row['ulevel2']==2){
                    $b3=$ffmey*$row_iul['yl10']/100/$xing2['c2'];
                }elseif($row['ulevel2']==3){
                    $b3=$ffmey*$row_iul['yl11']/100/$xing3['c3'];
                }elseif($row['ulevel2']==4){
                    $b3=$ffmey*$row_iul['yl12']/100/$xing4['c4'];
                }elseif($row['ulevel2']==5){
                    $b3=$ffmey*$row_iul['yl13']/100/$xing5['c5'];
                }
            $bpd = $this->pdsx($row['id'],$b3,3);
                if($bpd[0]>0&&$row['cishu']==1){
                    if($bpd[1]==1){
                        $beizhu = $bpd[0]."业绩奖（封顶）";
                    }else{
                        $beizhu = $bpd[0]."业绩奖";
                    }
                    edit_sql("update `member` set b3=b3+{$bpd[0]},zfmaxmey=zfmaxmey+{$bpd[0]} where id=".$row['id']." ");
                    $this->bonus_laiyuan($row['id'],$row['nickname'],$row['id'],$row['nickname'],3,$bpd[0],$beizhu);
                }
            }
    }
    /**
     * 极差奖
     * */

    function b3bonus($uid,$nickname,$rep,$rel,$isjc){
        $us=getMemberbyID($uid);
        $lsk=$isjc;
        $_ulevel_cl=new ulevel_class();
        $sql="select * from `member` where id in(0".$rep."0) and ".$rel."-relevel<=".$rel." and ulevel2>0  and ulevel>1 order by relevel desc ";
        if($query = mysql_query($sql)){
            while ($row=mysql_fetch_array($query)){
                $num1=0;
                $num2=0;
                $num3=0;
                $num4=0;
                $newus=getMemberbyID($uid);
                $_iul=$_ulevel_cl->getulevelbyulevel($row['ulevel']);
                $b4=0;
                if($row['ulevel2']==1&&$newus['area3']==0&&$newus['area4']==0&&$newus['area5']==0&&$newus['area6']==0&&$newus['area7']==0){
                    $num1=xingji($uid,$nickname,$rep,$rel,$row['ulevel2']);

                    //  edit_sql("update `member` set area3=1 where id=".$newus['id']." ");
                    if($newus['narea3']+1==$num1){
                        $b4=0.005*$lsk;
                        edit_sql("update `member` set area3=1 where id=".$newus['id']." ");
                    }else{
                        if($newus['narea3']==0){
                            $b4=$_iul['yl19']/100*$lsk;
                        }else{
                            $b4=0.005*$lsk;
                        }
                        $narea3=$newus['narea3']+1;
                        edit_sql("update `member` set narea3={$narea3} where id=".$newus['id']." ");
                    }
                }else if($row['ulevel2']==2&&$newus['area4']==0&&$newus['area5']==0&&$newus['area6']==0&&$newus['area7']==0){
                    $num2=xingji($uid,$nickname,$rep,$rel,$row['ulevel2']);
                    if($newus['narea4']==0){
                        if($newus['area3']==0){
                            $b4=$_iul['yl20']/100*$lsk;
                        }else{
                            $b4=($_iul['yl20']-$_iul['yl19'])/100*$lsk;
                        }
                    }else{
                        $b4=0.005*$lsk;
                    }
                    if($newus['narea4']+1==$num2){
                        edit_sql("update `member` set area4=1 where id=".$newus['id']." ");
                    }else{
                        $narea4=$newus['narea4']+1;
                        edit_sql("update `member` set narea4={$narea4} where id=".$newus['id']." ");
                    }
                }else if($row['ulevel2']==3&&$newus['area5']==0&&$newus['area6']==0&&$newus['area7']==0){
                    $num3=xingji($uid,$nickname,$rep,$rel,$row['ulevel2']);
                    if($newus['narea5']==0){
                        if($newus['area3']==1){
                            $a3=$_iul['yl19'];
                            if($newus['area4']==1){
                                $a4=$_iul['yl20']-$a3;
                            }else{
                                $a4=0;
                            }
                        }else{
                            $a3=0;
                            if($newus['area4']==1){
                                $a4=$_iul['yl20']-$a3;
                            }else{
                                $a4=0;
                            }
                        }
                        $ul=$_iul['yl21']-$a3-$a4;
                        $b4=$ul/100*$lsk;
                    }else{
                        $b4=0.005*$lsk;
                    }
                    if($newus['narea5']+1==$num3){
                        edit_sql("update `member` set area5=1 where id=".$newus['id']." ");
                    }else{
                        $narea5=$newus['narea5']+1;
                        edit_sql("update `member` set narea5={$narea5} where id=".$newus['id']." ");
                    }
                    //    edit_sql("update `member` set area5=1 where id=".$newus['id']." ");
                }else if($row['ulevel2']==4&&$newus['area6']==0&&$newus['area7']==0){
                    $num4=xingji($uid,$nickname,$rep,$rel,$row['ulevel2']);
                    if($newus['narea6']==0){
                        if($newus['area3']==1){
                            $a3=$_iul['yl19'];
                            if($newus['area4']==1){
                                $a4=$_iul['yl20']-$a3;
                                if($newus['area5']==1){
                                    $a5=$_iul['yl21']-$a4-$a3;
                                }else{
                                    $a5=0;
                                }
                            }else{
                                $a4=0;
                                if($newus['area5']==1){
                                    $a5=$_iul['yl7']-$a4-$a3;
                                }else{
                                    $a5=0;
                                }
                            }
                        }else{
                            $a3=0;
                            if($newus['area4']==1){
                                $a4=$_iul['yl20']-$a3;
                                if($newus['area5']==1){
                                    $a5=$_iul['yl21']-$a4-$a3;
                                }else{
                                    $a5=0;
                                }
                            }else{
                                $a4=0;
                                if($newus['area5']==1){
                                    $a5=$_iul['yl21']-$a4-$a3;
                                }else{
                                    $a5=0;
                                }
                            }
                        }
                        $ul=$_iul['yl22']-$a3-$a4-$a5;
                        $b4=$ul/100*$lsk;
                    }else{
                        $b4=0.005*$lsk;
                    }
                    if($newus['narea6']+1==$num4){
                        edit_sql("update `member` set area6=1 where id=".$newus['id']." ");
                    }else{
                        $narea6=$newus['narea6']+1;
                        edit_sql("update `member` set narea6={$narea6} where id=".$newus['id']." ");
                    }
                    //  edit_sql("update `member` set area6=1 where id=".$newus['id']."");
                }elseif($row['ulevel2']==5&&$newus['area7']==0){
                    $num5=xingji($uid,$nickname,$rep,$rel,$row['ulevel2']);
                    if($newus['narea7']==0){
                        if($newus['area3']==1){
                            $a3=$_iul['yl19'];
                            if($newus['area4']==1){
                                $a4=$_iul['yl20']-$a3;
                                if($newus['area5']==1){
                                    $a5=$_iul['yl21']-$a4-$a3;
                                    if($newus['area6']==1){
                                        $a6=$_iul['yl22']-$a5-$a4-$a3;
                                    }else{
                                        $a6=0;
                                    }
                                }else{
                                    $a5=0;
                                    if($newus['area6']==1){
                                        $a6=$_iul['yl22']-$a5-$a4-$a3;
                                    }else{
                                        $a6=0;
                                    }
                                }
                            }else{
                                $a4=0;
                                if($newus['area5']==1){
                                    $a5=$_iul['yl21']-$a4-$a3;
                                    if($newus['area6']==1){
                                        $a6=$_iul['yl22']-$a5-$a4-$a3;
                                    }else{
                                        $a6=0;
                                    }
                                }else{
                                    $a5=0;
                                    if($newus['area6']==1){
                                        $a6=$_iul['yl22']-$a5-$a4-$a3;
                                    }else{
                                        $a6=0;
                                    }
                                }
                            }
                        }else{
                            $a3=0;
                            if($newus['area4']==1){
                                $a4=$_iul['yl20']-$a3;
                                if($newus['area5']==1){
                                    $a5=$_iul['yl21']-$a4-$a3;
                                    if($newus['area6']==1){
                                        $a6=$_iul['yl22']-$a5-$a4-$a3;
                                    }else{
                                        $a6=0;
                                    }
                                }else{
                                    $a5=0;
                                    if($newus['area6']==1){
                                        $a6=$_iul['yl22']-$a5-$a4-$a3;
                                    }else{
                                        $a6=0;
                                    }
                                }
                            }else{
                                $a4=0;
                                if($newus['area5']==1){
                                    $a5=$_iul['yl21']-$a4-$a3;
                                    if($newus['area6']==1){
                                        $a6=$_iul['yl22']-$a5-$a4-$a3;
                                    }else{
                                        $a6=0;
                                    }
                                }else{
                                    $a5=0;
                                    if($newus['area6']==1){
                                        $a6=$_iul['yl22']-$a5-$a4-$a3;
                                    }else{
                                        $a6=0;
                                    }
                                }
                            }
                        }
                        $ul=$_iul['yl23']-$a3-$a4-$a5-$a6;
                        $b4=$ul/100*$lsk;
                    }else{
                        $b4=0.005*$lsk;
                    }
                    if($newus['narea7']+1==$num5){
                        edit_sql("update `member` set area7=1 where id=".$newus['id']." ");
                    }else{
                        $narea7=$newus['narea7']+1;
                        edit_sql("update `member` set narea7={$narea7} where id=".$newus['id']." ");
                    }
                }
                if($b4>0&&$row['cishu']==1){
                    $beizhu=$b4."领导奖";
                    edit_sql("update `member` set b4=b4+".$b4." where id=".$row['id']." ");
                    $this->bonus_laiyuan($row['id'],$row['nickname'],$uid,$nickname,4,$b4,$beizhu);
                    //     $this->b5bonus($row['id'],$b4);
                }
                //
            }
        }
 /*       $sql="select * from member where ulevel2=5";
        $query=getAll($sql);
        $query2=mysql_query($sql);
        $num=count($query);
        while ($row2=mysql_fetch_assoc($query2)){
            $_iul2=$_ulevel_cl->getulevelbyulevel($row2['ulevel']);
            $b41=$_iul2['yl9']/100*$lsk/$num;
            if($b41>0){
                $beizhu2=$b41."极差分红";
                edit_sql("update `member` set b4=b4+".$b41." where id=".$row2['id']." ");
                $this->bonus_laiyuan($row2['id'],$row2['nickname'],$uid,$nickname,3,$b41,$beizhu2);
            }
        }*/
        edit_sql("update `member` set area3=0,area4=0,area5=0,area6=0,narea3=0,narea4=0,narea5=0,narea6=0,narea7=0 where id=".$us['id']." ");
    }

    //层碰：
    function cengpeng($id){
        $system=new system_class();
        $_sys=$system->system_information(1);
        $me=getMemberbyID($id);
        $sql="select * from member where plevel=".$me['plevel']." and ispay=1 and id<>{$me['id']} order by pdt";
        $row=getAll($sql);//得到激活会员同一层所有的会员
        $con=count($row);//人数
        $path=ppath($me['id']);
        $lsk = 0;
        for($z=0;$z<$con;$z++){//从第一个会员开始遍历所有会员
            //拆分b的ppath
            $arr2=ppath($row[$z]['id']);//第一个会员的关系链
            $num=count($arr2);//关系链里的人数
            $num-=1;
            for($i=$num;$i>=0;$i--){//从两个会员关系链的最下层开始
                if($path[$i]==$arr2[$i]){//是否是共同接点人
                    $us=getMemberbyID($arr2[$i]);
                    //找到激活会员的共同接点人所在层的激活时间顺序
                //    $pl=$me['plevel']-$us['plevel'];
                        $ulevel_cl = new ulevel_class ();
                        $iul=$ulevel_cl->getulevelbyulevel($us['ulevel']);
                        ///取小单进行层碰
                        $lsk=$me['lsk']>=$row[$z]['lsk']?$row[$z]['lsk']:$me['lsk'];
                        $cha=$me['plevel']-$us['plevel'];
                        $m=$iul['yl2'];

                        //取小单费率结束
                        if($us['zb1']<$me['plevel']){
                 /*           $treeplace=gettreeplace($me['id'],$us['id']);
                            if(empty($treeplace)){
                                $treeplace=$me['treeplace'];
                            }
                            if($treeplace==1){
                                $_member_update['yarea1']=$us['yarea1']-$me['lsk'];
                                $_member_update['yarea2']=$us['yarea2']-$row[$z]['lsk'];
                            }else{
                                $_member_update['yarea1']=$us['yarea1']-$row[$z]['lsk'];
                                $_member_update['yarea2']=$us['yarea2']-$me['lsk'];
                            }
                            edit_update_cl('member',$_member_update,$us['id']);*/
                            if($m>0){
                                $beizhu = $m."绩效奖";
                                if($cha==2){
                                    edit_sql("update `member` set wlf=wlf+{$m},zb1={$me['plevel']} where id=".$us['id']." ");
                                }elseif($cha>12&&$cha<18){
                                    edit_sql("update `member` set cfxf=cfxf+{$m},zb1={$me['plevel']} where id=".$us['id']." ");
                                }else{
                                    edit_sql("update `member` set b2=b2+{$m},zb1={$me['plevel']} where id=".$us['id']." ");
                                }
                                $this->bonus_laiyuan($us['id'],$us['nickname'],0,"{$cha}层",2,$m,$beizhu);
                            }
                    }
                    break;
                }
            }
        }
    }

    //见点奖
    function b2bonus2($uid,$nickname,$rep,$rel){
        $_ulevel_cl=new ulevel_class();
        $us=getMemberbyID($uid);
        $sql="select * from `member` where id in(0".$rep."0) and ".$rel."-plevel<=".$rel." ";
        if($query = mysql_query($sql)){
            while ($row=mysql_fetch_array($query)){
         //       if($row['zfmey']==0){
                    $cha=$us['plevel']-$row['plevel'];
                    $_iul=$_ulevel_cl->getulevelbyulevel($row['ulevel']);
                    if($cha==1){
                        $b1=$_iul['yl1'];
                    }elseif($cha==2){
                        $b1=$_iul['yl2'];
                    }elseif($cha==3){
                        $b1=$_iul['yl3'];
                    }elseif($cha==4){
                        $jian=jianmey($row['id'],$cha);
                        if(empty($jian)){
                            addjiandianmey($row['id'],$cha, $_iul['yl4']);
                            $beizhu='扣除升级费用';
                            $this->bonus_laiyuan($row['id'],$row['nickname'],$uid,$nickname,11,$_iul['yl4'],$beizhu);
                        }elseif($jian['jine']<$_iul['yl16']){
                            $b1=updatejiandianmey($jian['jine'],$_iul['yl16'],$jian['id'],$_iul['yl4'],$row['id']);
                        }else{
                            $b1=$_iul['yl4'];
                        }
                    }elseif($cha==5){
                        $jian=jianmey($row['id'],$cha);
                        if(empty($jian)){
                            addjiandianmey($row['id'],$cha, $_iul['yl5']);
                            $beizhu='扣除升级费用';
                            $this->bonus_laiyuan($row['id'],$row['nickname'],$uid,$nickname,11,$_iul['yl5'],$beizhu);
                        }elseif($jian['jine']<$_iul['yl17']){
                            $b1=updatejiandianmey($jian['jine'],$_iul['yl17'],$jian['id'],$_iul['yl5'],$row['id']);
                        }else{
                            if($row['istiche']==0&&$row['chuju']<20000){
                                if($row['chuju']+$_iul['yl5']>20000){
                                    $b1=$row['chuju']+$_iul['yl5']-20000;
                                    edit_sql("update member set chuju=20000 where id=".$row['id']);
                                }else{
                                    $b1=0;
                                    edit_sql("update member set chuju=chuju+{$_iul['yl5']} where id=".$row['id']);
                                }
                                $beizhu='扣除2万';
                                $this->bonus_laiyuan($row['id'],$row['nickname'],$uid,$nickname,11,$_iul['yl5'],$beizhu);
                            }else{
                                $b1=$_iul['yl5'];
                            }
                        }

                    }elseif($cha==6){
                        $jian=jianmey($row['id'],$cha);
                        if(empty($jian)){
                            addjiandianmey($row['id'],$cha, $_iul['yl6']);
                            $beizhu='扣除升级费用';
                            $this->bonus_laiyuan($row['id'],$row['nickname'],$uid,$nickname,11,$_iul['yl6'],$beizhu);
                        }elseif($jian['jine']<$_iul['yl18']){
                            $b1=updatejiandianmey($jian['jine'],$_iul['yl18'],$jian['id'],$_iul['yl6'],$row['id']);
                        }else{
                            if($row['istiche']==0&&$row['chuju']<30000){
                                if($row['chuju']+$_iul['yl6']>30000){
                                    $b1=$row['chuju']+$_iul['yl6']-30000;
                                    edit_sql("update member set chuju=30000 where id=".$row['id']);
                                }else{
                                    $b1=0;
                                    edit_sql("update member set chuju=chuju+{$_iul['yl6']} where id=".$row['id']);
                                }
                                $beizhu='扣除3万';
                                $this->bonus_laiyuan($row['id'],$row['nickname'],$uid,$nickname,11,$_iul['yl6'],$beizhu);
                            }else{
                                $b1=$_iul['yl6'];
                            }
                          //  $b1=$_iul['yl6'];
                        }
                    }elseif($cha==7){
                        $jian=jianmey($row['id'],$cha);
                        if(empty($jian)){
                            addjiandianmey($row['id'],$cha, $_iul['yl7']);
                            $beizhu='扣除升级费用';
                            $this->bonus_laiyuan($row['id'],$row['nickname'],$uid,$nickname,0,$_iul['yl7'],$beizhu);
                        }elseif($jian['jine']<$_iul['yl19']){
                            $b1=updatejiandianmey($jian['jine'],$_iul['yl19'],$jian['id'],$_iul['yl7'],$row['id']);
                        }else{
                            if($row['istiche']==0&&$row['chuju']<50000){
                                if($row['chuju']+$_iul['yl7']>50000){
                                    $b1=$row['chuju']+$_iul['yl7']-50000;
                                    edit_sql("update member set chuju=50000 where id=".$row['id']);
                                }else{
                                    $b1=0;
                                    edit_sql("update member set chuju=chuju+{$_iul['yl7']} where id=".$row['id']);
                                }
                                $beizhu='扣除5万';
                                $this->bonus_laiyuan($row['id'],$row['nickname'],$uid,$nickname,11,$_iul['yl7'],$beizhu);
                            }else{
                                $b1=$_iul['yl7'];
                            }
                         //   $b1=$_iul['yl7'];
                        }
                    }elseif($cha==8){
                        $jian=jianmey($row['id'],$cha);
                        if(empty($jian)){
                            addjiandianmey($row['id'],$cha, $_iul['yl8']);
                            $beizhu='扣除升级费用';
                            $this->bonus_laiyuan($row['id'],$row['nickname'],$uid,$nickname,11,$_iul['yl8'],$beizhu);
                        }elseif($jian['jine']<$_iul['yl20']){
                            $b1=updatejiandianmey($jian['jine'],$_iul['yl20'],$jian['id'],$_iul['yl8'],$row['id']);
                        }else{
                            $b1=$_iul['yl8'];
                        }
                    }elseif($cha==9){
                        $jian=jianmey($row['id'],$cha);
                        if(empty($jian)){
                            addjiandianmey($row['id'],$cha, $_iul['yl9']);
                            $beizhu='扣除升级费用';
                            $this->bonus_laiyuan($row['id'],$row['nickname'],$uid,$nickname,11,$_iul['yl9'],$beizhu);
                        }elseif($jian['jine']<$_iul['yl21']){
                            $b1=updatejiandianmey($jian['jine'],$_iul['yl21'],$jian['id'],$_iul['yl9'],$row['id']);
                        }else{
                            $b1=$_iul['yl9'];
                        }
                    }elseif($cha==10){
                        $jian=jianmey($row['id'],$cha);
                        if(empty($jian)){
                            addjiandianmey($row['id'],$cha, $_iul['yl10']);
                            $beizhu='扣除升级费用';
                            $this->bonus_laiyuan($row['id'],$row['nickname'],$uid,$nickname,11,$_iul['yl10'],$beizhu);
                        }elseif($jian['jine']<$_iul['yl22']){
                            $b1=updatejiandianmey($jian['jine'],$_iul['yl22'],$jian['id'],$_iul['yl10'],$row['id']);
                        }else{
                            $b1=$_iul['yl10'];
                        }
                    }elseif($cha>=11&&$cha<=33){
                        $jian=jianmey($row['id'],$cha);
                        if(empty($jian)){
                            addjiandianmey($row['id'],$cha, $_iul['yl11']);
                            $beizhu='扣除升级费用';
                            $this->bonus_laiyuan($row['id'],$row['nickname'],$uid,$nickname,11,$_iul['yl11'],$beizhu);
                        }elseif($jian['jine']<$_iul['yl23']){
                            $b1=updatejiandianmey($jian['jine'],$_iul['yl23'],$jian['id'],$_iul['yl11'],$row['id']);
                        }else{
                            $b1=$_iul['yl11'];
                        }
                    }
                /*        $bpd = $this->pdsx($row['id'],$b2,1);
                        if($bpd[0]>0) {
                            if ($bpd[1] == 1) {
                                $beizhu = $bpd[0] . "见点奖(封顶)";
                            } else {
                                $beizhu = $bpd[0] . "见点奖";
                            }
                            edit_sql("update `member` set b1=b1+".$bpd[0].",xytuijian=xytuijian+{$bpd[0]} where id=".$row['id']." ");
                            $this->bonus_laiyuan($row['id'],$row['nickname'],$uid,$nickname,1,$bpd[0],$beizhu);
                        }*/
                            if($b1>0){
                                   $beizhu=$cha."代".$b1."分享奖";
                                   edit_sql("update `member` set b1=b1+".$b1." where id=".$row['id']." ");
                                   $this->bonus_laiyuan($row['id'],$row['nickname'],$uid,$nickname,1,$b1,$beizhu);
                               }
         //       }

            }
        }
    }


    //碰对加封顶
    function b3bonusd(){
        $_member = new member_class();
        $_ulevel_cl=new ulevel_class();
        $sql="SELECT * FROM `member` where yarea1>0 and yarea2>0 and ispay>0 and man=1 ";
        if($query = mysql_query($sql)){
            while ($row=mysql_fetch_array($query)){
                $_member_update=NULL;
                $y1=$row['yarea1'];
                $y2=$row['yarea2'];
                $dan=0;
                if($y1>=$y2){
                    $dan=$y2;
                    $y1=$y1-$y2;
                    $y2=0;
                }elseif($y1<=$y2){
                    $dan=$y1;
                    $y2=$y2-$y1;
                    $y1=0;
                }
                if ($dan>0){
                    $_member_update['yarea1']=$y1;
                    $_member_update['yarea2']=$y2;
                    edit_update_cl('member',$_member_update,$row['id']);
                    $_iul=$_ulevel_cl->getulevelbyulevel($row['ulevel']);
             /*       if($row['maxmey']>=$_iul['yl13']){
                        $b3=$_iul['yl14']*$dan/100;
                    }else{*/
                        $b3=$_iul['yl2']*$dan/100;
               //     }

                    if($b3>0){
                            $beizhu=$b3."元碰对奖";
                        edit_sql("update `member` set b3=b3+".$b3." where id=".$row['id']." ");
                        $this->bonus_laiyuan($row['id'],$row['nickname'],0,"-",3,$b3,$beizhu);
                        $this->b5bonus2($row['id'],$b3);
                    }/*
                             $bpd = $this->pdsx($row['id'],$b3,2);
                          if($bpd[0]>0){
                        if($row['zfmaxmey']>0){
                            $bpd[0]=$bpd[0]-$row['zfmaxmey'];
                        }
                        if($bpd[1]==1){
                            $beizhu=$bpd[0]."碰对奖(封顶)";
                        }else{
                            $beizhu=$bpd[0]."元碰对奖";
                        }
                        edit_sql("update `member` set b3=b3+".$bpd[0].",zfmey=zfmey+{$bpd[0]} where id=".$row['id']." ");
                        $this->bonus_laiyuan($row['id'],$row['nickname'],0,"-",3,$bpd[0],$beizhu);

                    }*/
                }
            }
        }
    }
    //帮扶奖
    function b5bonus($id,$mey){
        $user=getMemberbyID($id);
        $ulevel_cl = new ulevel_class ();
        $relevel1=$user['relevel']+1;
        $relevel2=$user['relevel']+2;
        $sql="select * from `member` where repath like '%{$user['repath']}%'and ispay>0 and (relevel={$relevel1} or relevel={$relevel2})and man=1";
        $query=mysql_query($sql);
        $sql="select COUNT(*) as num1 from `member` where repath like '%{$user['repath']}%'and ispay>0 and relevel={$relevel1} and man=1";
        $num1=getOne($sql);
        $sql="select COUNT(*) as num2 from `member` where repath like '%{$user['repath']}%'and ispay>0 and relevel={$relevel2} and man=1";
        $num2=getOne($sql);
        while ($row=mysql_fetch_assoc($query)) {
            $ulevel = $ulevel_cl->getulevelbyulevel($row['ulevel']);
            $cha=$row['relevel']-$user['relevel'];
            if($cha==1){
                $b4 = round($mey * $ulevel['yl3'] / 100/$num1['num1'], 2);
            }else if($cha==2){
                $b4 = round($mey * $ulevel['yl4'] / 100/$num2['num2'], 2);
            }
         //   $bpd = $this->pdsx($row['id'],$b4,1);
            if($b4>0){
            /*    if($bpd[1]==1){
                    $beizhu=$b4."下拿领导奖(封顶)";
                }else{*/
                    $beizhu=$cha."代".$b4."帮扶奖";
           //     }
                edit_sql("update `member` set b4=b4+".$b4." where id=".$row['id']." ");
                $this->bonus_laiyuan($row['id'], $row['nickname'], $user['id'], $user['nickname'], 4, $b4, $beizhu);

            }
        }

    }

    //领导奖
    function b5bonus2($id,$mey){
        $user=getMemberbyID($id);
        $ulevel_cl = new ulevel_class ();
        $sql="select * from `member` where id in(0".$user['repath']."0) and ".$user['relevel']."-relevel<=2  and man=1";
        $query=mysql_query($sql);
        while ($row=mysql_fetch_assoc($query)) {
            $sql="select COUNT(*) as num1 from `member` where id in(0".$user['repath']."0) and ".$user['relevel']."-relevel=1";
            $num1=getOne($sql);
            $sql="select COUNT(*) as num2 from `member` where id in(0".$user['repath']."0) and ".$user['relevel']."-relevel=2";
            $num2=getOne($sql);
            $ulevel = $ulevel_cl->getulevelbyulevel($row['ulevel']);
            $cha=$user['relevel']-$row['relevel'];
            if($cha==1){
                $b2 = round($mey * $ulevel['yl5'] / 100/$num1['num1'], 2);
            }else if($cha==2){
                $b2 = round($mey * $ulevel['yl6'] / 100/$num2['num2'], 2);
            }
/*            $bpd = $this->pdsx($row['id'],$b4,1);
            if($bpd[0]>0){
                if($bpd[1]==1){
                    $beizhu=$bpd[0]."下拿管理奖(封顶)";
                }else{
                    $beizhu=$bpd[0]."下拿管理奖";
                }*/
                if($b2>0){
                    $beizhu=$b2."下拿领导奖";
                edit_sql("update `member` set b2=b2+".$b2." where id=".$row['id']." ");
                $this->bonus_laiyuan($row['id'], $row['nickname'], $user['id'], $user['nickname'], 2, $b2, $beizhu);
            }
        }

 /*       $sql="select * from member where relevel=(".$user['relevel']."+2) or relevel=(".$user['relevel']."+1)" ;
        $alluser=getAll($sql);
        $sum=0;
        foreach ($alluser as $key=>$value){
            $vrepath=trim($value['repath'],",");
            $repath=explode(",",$vrepath);
            if(in_array($id,$repath)){
                $arr[]=$value['id'];
                $sum+=1;
            }
        }
        foreach ($arr as $key=>$value2){
            $me=getMemberbyID($value2);
            $ulevel=$ulevel_cl->getulevelbyulevel($me['ulevel']);
            $b4=round($mey*$ulevel['yl7']/100/$sum,2);

         if($b4>0){
             $beizhu=$b4."上拿管理奖";
                edit_sql("update `member` set b4=b4+".$b4." where id=".$me['id']." ");
                $this->bonus_laiyuan($me['id'], $me['nickname'], $user['id'], $user['nickname'], 4, $b4, $beizhu);
            }
        }*/


    }

    //日封顶
    function ldfd($id, $b6) {
        $user = getMemberbyID ( $id );
        $ulevel_cl = new ulevel_class ();
        $ulevel = $ulevel_cl->getulevelbyulevel ($user['ulevel']);
        $ulevel_jine = $ulevel ['yl8']*$user['lsk']; // 得到封顶
        $mey = $ulevel_jine - $user['xytuijian'];
        if ($mey>0){
            if ($mey>$b6) {
                return array($b6,0);
            } elseif($mey==$b6){
                return array($b6,1);
            } else{
                return array($mey,1);
            }
        } else {
            return array(0,0);
        }
    }
    //日封顶
    function bmemberpdsx($id, $b6,$fengding) {
        $riQi = date ( "Y-m-d" );
        $user = getBMemberby ( $id );
        $ulevel_cl = new ulevel_class ();
        $bonus = getdaybonus ($id,$riQi);
        $ulevel = $ulevel_cl->getulevelbyulevel ($user['ulevel']);
        if($fengding==1){
            $ulevel_jine = $ulevel ['yl15']; // 得到封顶
            $mey = $ulevel_jine - $user['zfmey'];
        }elseif($fengding==2){
            $ulevel_jine = $user ['lsk']*$ulevel['yl7']; // 得到封顶
            $mey = $ulevel_jine - $bonus['b3'];
        }
        if ($mey>0){
            if ($mey>$b6) {
                return array($b6,0);
            } elseif($mey==$b6){
                return array($b6,1);
            } else{
                return array($mey,1);
            }
        } else {
            return array(0,0);
        }
    }    //日封顶
    function pdsx($id,$b6,$fengding) {
        $riQi = date ( "Y-m-d" );
        $user = getMemberbyID($id);
        $ulevel_cl = new ulevel_class ();
        $bonus = getdaybonus ($id,$riQi);
        $ulevel = $ulevel_cl->getulevelbyulevel ($user['ulevel']);
        if($fengding==1){
            $ulevel_jine = $ulevel ['yl2']; // 得到封顶
            $mey = $ulevel_jine - $user['zfmey'];
        }elseif($fengding==2){
            $ulevel_jine = $user ['lsk']*$ulevel['yl7']; // 得到封顶
            $mey = $ulevel_jine - $bonus['b3'];
        }elseif($fengding==3){
            if($user['ulevel2']==1){
                $ulevel_jine=$ulevel['yl14'];
            }elseif($user['ulevel2']==2){
                $ulevel_jine=$ulevel['yl15'];
            }elseif($user['ulevel2']==3){
                $ulevel_jine=$ulevel['yl16'];
            }elseif($user['ulevel2']==4){
                $ulevel_jine=$ulevel['yl17'];
            }elseif($user['ulevel2']==5){
                $ulevel_jine=$ulevel['yl18'];
            }
            $mey = $ulevel_jine - $user['zfmaxmey'];
        }
        if ($mey>0){
            if ($mey>$b6) {
                return array($b6,0);
            } elseif($mey==$b6){
                return array($b6,1);
            } else{
                return array($mey,1);
            }
        } else {
            return array(0,0);
        }
    }


    function zongyejijiang($id){
        $us=getMemberbyID($id);
        $_iul=new ulevel_class();
        $_sys=new system_class();
        $sys=$_sys->system_information(1);
        $pv=$sys['jmf1']/100;
        $sql="select * from member where plevel2>0";
        $query=mysql_query($sql);
        while ($row=mysql_fetch_assoc($query)){
            $ul=$_iul->getulevelbyulevel($row['ulevel']);
            if($row['plevel2']==1){
                $b2=$ul['yl7']/100*$us['lsk']*$pv;
            }elseif($row['plevel2']==2){
                $b2=$ul['yl8']/100*$us['lsk']*$pv;
            }elseif($row['plevel2']==3){
                $b2=$ul['yl9']/100*$us['lsk']*$pv;
            }
            if($b2>0){
                $beizhu=$b2."业绩奖";
                edit_sql("update member set b2=b2+".$b2." where id=".$row['id']);
                $this->bonus_laiyuan($row['id'],$row['nickname'],$us['id'],$us['nickname'],2,$b2,$beizhu);
            }
        }
    }
    //静态发放
    function bonus1($id,$date){
        $us=getMemberbyID($id);
        $_ulevel=new ulevel_class();
        $_iul=$_ulevel->getulevelbyulevel($us['ulevel']);
        if($_iul['yl5']>0){
            $b1=$_iul['yl5']*$us['lsk']/100;
        }
        $bpd = $this->pdsx($us['id'],$b1,1);
        if($bpd[0]>0){
            if($bpd[1]==1){
                $beizhu=$bpd[0]."静态奖(封顶)";
            }else{
                $beizhu=$bpd[0]."静态奖";
            }
            edit_sql("update `member` set b2=b2+".$bpd[0].",zfmey=zfmey+{$bpd[0]},qiandao={$date} where id=".$us['id']." ");
            $this->bonus_laiyuan($us['id'],$us['nickname'],$us['id'],$us['nickname'],2,$bpd[0],$beizhu);
        }
    }
    //静态
    function b1bonus1($id)
    {
        $user = getMemberbyID($id);
        $_ulevel_cl = new ulevel_class();
        $iul = $_ulevel_cl->getulevelbyulevel($user['ulevel']);
        if ($user['recount'] >= 2) {
            $b1 = $iul['yl8'];
        } else {
            $time=time();
            $pdt=strtotime($user['pdt']);
            $onemonth=strtotime("+1 months",$pdt);
            $towmonth=strtotime("+2 months",$pdt);
            $b1=0;
            if($time>=$onemonth&&$time<$towmonth){
                $b1=$iul['yl15'];
            }else if($time>=$towmonth){
                $b1=$iul['yl16'];
            }else if($time<$onemonth){
                $b1=$iul['yl8'];
            }
         }
            $bpd = $this->pdsx($id, $b1, 1);
            if ($bpd[0] > 0) {
                if ($bpd[1] == 1) {
                    $beizhu = $bpd[0] . "静态奖(封顶)";
                } else {
                    $beizhu = $bpd[0] . "静态奖";
                }
                    edit_sql("update `member` set b5=b5+" . $bpd[0] . ",zfmey=zfmey+".$bpd[0]." where id=" . $id . " ");
                    $this->bonus_laiyuan($user['id'], $user['nickname'], $user['id'], $user['nickname'], 5, $bpd[0], $beizhu);
                    $this->b0bonus();


            }

    }

    // 日结周发
    function rjzf(){
        $sql="select * from member where zfmey>0 and zfmaxmey>0";
        $query = mysql_query($sql);
        while ($row=mysql_fetch_array($query)){
            $_member_update['zfmey']=0;
            $_member_update['zfmaxmey']=0;
            $_member_update['mey']=$row['zfmey'];
            $_member_update['maxmey']=$row['zfmaxmey'];
            edit_update_cl('member',$_member_update,$row['id']);
            $beizhu=$row['zfmey']."积分币发放";
            $this->bonus_laiyuan($row['id'],$row['nickname'],"","",7,$row['zfmey'],$beizhu);
        }
    }










    function xingyun($id,$m){
        $ulevel_cl = new ulevel_class ();
        $uid = getMemberbyID($id);
        $sql="SELECT * FROM `member` WHERE UNIX_TIMESTAMP('".$uid['pdt']."') > UNIX_TIMESTAMP(pdt) order by pdt limit 20";
        if($query=mysql_query($sql)){
            while ($row=mysql_fetch_array($query)){
                $iul = $ulevel_cl->getulevelbyulevel (1);
                $b1 = $m/100*$iul['yl4'];
                $b1 = $b1/20;//得出20人的份
                if($row['recount']<=2){//判断没有推荐人会员
                    $bei = $row['lsk']*2;
                    if($bei>$row['xytuijian']){//判断拿的奖有没有达到自己投资额的2倍
                        edit_sql ( "update `member` set b1=b1+$b1,xytuijian=xytuijian+$b1 where id=".$row ['id']."" );
                        $beizhu=$b1."幸运奖";
                        $this->bonus_laiyuan($row['id'],$row['nickname'],$uid['id'],$uid['nickname'],1,$b1,$beizhu);
                    }
                }elseif ($row['recount']<=4){//判断推荐到2个会员
                    $bei = $row['lsk']*4;
                    if($bei>$row['xytuijian']){//判断拿的奖有没有小于自己投资额的4倍
                        edit_sql ( "update `member` set b1=b1+$b1,xytuijian=xytuijian+$b1 where id=".$row ['id']."" );
                        $beizhu=$b1."幸运奖";
                        $this->bonus_laiyuan($row['id'],$row['nickname'],$uid['id'],$uid['nickname'],1,$b1,$beizhu);
                    }
                }elseif ($row['recount']>=5){//判断推荐人会员有没有超过5个会员
                    edit_sql ( "update `member` set b1=b1+$b1,xytuijian=xytuijian+$b1 where id=".$row ['id']."" );
                    $beizhu=$b1."幸运奖";
                    $this->bonus_laiyuan($row['id'],$row['nickname'],$uid['id'],$uid['nickname'],1,$b1,$beizhu);
                }
            }
        }
    }


    //B网见点奖
    function b3bwonus($uid,$nickname,$rep,$rel){
        $_ulevel_cl=new ulevel_class();
        $sql="select * from `member` where id in(0".$rep."0) and ".$rel."-plevel2<=".$rel."";
        if($query = mysql_query($sql)){
            while ($row=mysql_fetch_array($query)){
                $cha=$rel-$row['plevel2'];
                $_iul=$_ulevel_cl->getulevelbyulevel($row['ulevel']);
                if($cha<=$_iul['yl5']){//判断层数
                    $b5=$_iul['yl6'];
                    if($b5>0){
                        edit_sql("update `member` set b5=b5+".$b5." where id=".$row['id']."");
                        $beizhu=$_iul['yl5']."B网见点奖";
                        $this->bonus_laiyuan($row['id'],$row['nickname'],$uid,$nickname,5,$b5,$beizhu);
                    }
                }
            }
        }
    }
    //找到10层全满的人
    function ceng($uid,$nickname,$rep,$rel){
        $_ulevel_cl=new ulevel_class();
        $sql="select * from `member` where id in(0".$rep."0) and ".$rel."-plevel<=".$rel."";
        if($query = mysql_query($sql)){
            while ($row=mysql_fetch_array($query)){
                $cha=$rel-$row['plevel'];
                $_iul=$_ulevel_cl->getulevelbyulevel(1);
                $man=1;
                if($cha<=10){
                    edit_sql("update `member` set man = man +".$man." where id=".$row['id']."");

                }
            }
        }
    }

    function fwzx(){
        $sql="select * from member where ulevel=4 and area1>=3000 and area2>=3000";
        if($query=mysql_query($sql)){
            while ($row=mysql_fetch_array($query)){
                $sql1="select * from member where ulevel=4 and reid=".$row['id'];
                $query1=mysql_query($sql1);
                if(mysql_num_rows($query1)>=2){
                    edit_sql("update `member` set sqfwzx = 1 where id=".$row['id']."");//给所有1级的会员升级为2级
                }
            }
        }
    }

    //加权平分
    function oldb4bonus($uid,$nickname){
        $_ulevel_cl=new ulevel_class();
        $sql="select * from member where ulevel>1 and ulevel<7";
        if($query=mysql_query($sql)){
            while($row=mysql_fetch_array($query)){
                $_iul=$_ulevel_cl->getulevelbyulevel(1);
                $rs=getUlevel();
                $nc=$_iul['yl3']/100*$_iul['yl6'];
                $b3=$nc/$rs;
                if($b3>0){
                    edit_sql("update `member` set b3=b3+".$b3.",Upgrade=Upgrade+".$b3." where id=".$row['id']."");
                    $beizhu=$b3."加权平分";
                    $this->bonus_laiyuan($row['id'],$row['nickname'],$uid,$nickname,3,$b3,$beizhu);
                }
            }
        }
    }


    //运管部积分
    function yunguanbu($lsk){
        $rs=getMemberbyID(1);
        //保单or升级都会给运管部5%奖币
        $b1=5*$lsk/100;
        edit_sql ( "update `member` set b1=b1+$b1 where id=1" );
    }

    function shiqu($id, $lsk) {
        $b1=2*$lsk/100;
        $us = getMemberbyID ( $id );
        $sql = "select * from city where cityid=" . $us ['shi'] . "";
        $query = mysql_query ( $sql );
        if ($row = mysql_fetch_assoc ( $query )) {
            if ($b1 > 0) {
                edit_sql ( "update `city` set b1=b1+$b1 where id=" . $row ['id'] . "" );
            }
        }
    }

    // 分运管部和市区办1%
    function gouwufh($id, $nickname, $lsk) {
        $us = getMemberbyID ( $id );
        $sql = "select * from city where cityid=" . $us ['shi'] . "";
        $query = mysql_query ( $sql );
        if ($row = mysql_fetch_assoc ( $query )) {
            $b4 = $lsk * 0.01;
        }
        if ($b4 > 0) {
            edit_sql ( "update `city` set lsk=lsk+$b4 where id=" . $row ['id'] . "" );
            // $this->bonus_laiyuan($me['bdid'],$me['bdname'],$id,$nickname,4,$b4,"购物返利");
            edit_sql ( "update `member` set b4=b4+$b4 where id=1" );
            $this->bonus_laiyuan ( $us ['id'], $us ['nickname'], $id, $nickname, 4, $b4, "购物返利" );
        }
    }

    // 见点二级
    function b2bonus($uid, $nickname, $lsk, $ulevel) {
        $rs = getMemberbyID ( $uid );
        $_ulevel_cl = new ulevel_class ();
        if ($ulevel > 1) {
            for($i = 1; $i <= 3; $i ++) {
                $b2=0;
                $us = getMemberbyID ( $uid );
                $uid = $us ['fatherid2'];
                $uss = getMemberbyID ( $uid );
                $iul = $_ulevel_cl->getulevelbyulevel ( $us['ulevel'] );
                if ($us['fatherid2'] == 0) {
                    break;
                }
                if ($uss ['ulevel'] > 1) {
                    if ($ulevel == 2) {
                        $b2 = 30;
                    } elseif ($ulevel == 3) {
                        if ($uss['ulevel'] == 2) {
                            $b2 = 30;
                        }
                    } elseif ($ulevel == 4) {
                        if ($uss['ulevel'] == 2) {
                            $b2 = 30;
                        }
                    }
                }
                if ($b2 > 0) {
                    edit_sql ( "update `member` set b2=b2+$b2 where id=" . $uss ['id'] . "" );
                    $this->bonus_laiyuan ( $uss ['id'], $uss ['nickname'], $rs ['id'], $rs ['nickname'], 2, $b2, "见点分红" );
                    $this->b0bonus ( $uid, $nickname );
                    $this->b3bonus ( $uss ['id'], $uss ['nickname'], $b2 );
                }
            }
        }
    }
    // 见点
    function b2bonuss($uid, $nickname, $lsk, $ulevel) {
        $rs = getMemberbyID ( $uid );
        $_ulevel_cl = new ulevel_class ();
        if ($ulevel > 1) {
            for($i = 1; $i <= 10; $i ++) {
                $b2=0;
                $us = getMemberbyID ( $uid );
                $uid = $us ['fatherid2'];
                $uss = getMemberbyID ( $uid );
                $iul = $_ulevel_cl->getulevelbyulevel ( $us ['ulevel'] );
                if ($us ['fatherid2'] == 0) {
                    break;
                }
                if ($uss ['ulevel'] > 1) {
                    if ($ulevel == 3) {
                        if ($uss ['ulevel'] == 3 || $uss ['ulevel'] == 4) {
                            $b2 = 150;
                        } elseif ($uss ['ulevel'] == 2) {
                            $uid = $this->jinsuo ( $uss ['id'], $rs ['id'], $rs ['nickname'] );
                        }
                    } elseif ($ulevel == 4) {
                        if ($uss ['ulevel'] == 3) {
                            $b2 = 150;
                        } elseif ($uss ['ulevel'] == 2) {
                            $uid = $this->jinsuo1 ( $uss ['id'], $rs ['id'], $rs ['nickname'] );
                        }
                    }
                }
                if ($b2 > 0) {
                    edit_sql ( "update `member` set b2=b2+$b2 where id=" . $uss ['id'] . "" );
                    $this->bonus_laiyuan ( $uss ['id'], $uss ['nickname'], $rs ['id'], $rs ['nickname'], 2, $b2, "见点分红" );
                    $this->b0bonus ( $uid, $nickname );
                    $this->b3bonus ( $uss ['id'], $uss ['nickname'], $b2 );
                }
            }
        }

    }


    // 递归
    function jinsuo1j2($uid, $id, $nickname) {
        $b2=0;
        $us = getMemberbyID ( $uid );
        $uid = $us ['fatherid2'];
        $uss = getMemberbyID ( $uid );
        if ($us ['fatherid2'] == 0) {
            return ;
        }
        if ($uss [ulevel] == 4) {
            $b2 = 200;
            edit_sql ( "update `member` set b2=b2+$b2 where id=" . $uss ['id'] . "" );
            $this->bonus_laiyuan ( $uss ['id'], $uss ['nickname'], $id, $nickname, 2, $b2, "见点分红" );
            $this->b3bonus ( $uss ['id'], $uss ['nickname'], $b2 );
            return $uid;
        } else {
            return $this->jinsuo1j2 ( $uss ['id'], $id, $nickname );
        }
    }

    // 递归
    function jinsuo2($uid, $id, $nickname) {
        $b2=0;
        $us = getMemberbyID ( $uid );
        $uid = $us ['fatherid2'];
        $uss = getMemberbyID ( $uid );
        if ($us ['fatherid2'] == 0) {
            break;
        }
        if ($uss [ulevel] == 3 || $uss ['ulevel'] == 4) {
            $b2 = 100;
            edit_sql ( "update `member` set b2=b2+$b2 where id=" . $uss ['id'] . "" );
            $this->bonus_laiyuan ( $uss ['id'], $uss ['nickname'], $id, $nickname, 2, $b2, "见点分红" );
            $this->b3bonus ( $uss ['id'], $uss ['nickname'], $b2 );
            $this->b0bonus ( $uid, $nickname );
            return $uss ['id'];
        } else {
            return $this->jinsuo2 ( $uss ['id'], $rs ['id'], $rs ['nickname'] );
        }
    }
    // 递归
    function jinsuo22($uid, $id, $nickname) {
        $b2=0;
        $us = getMemberbyID ( $uid );
        $uid = $us ['fatherid2'];
        $uss = getMemberbyID ( $uid );
        if ($us ['fatherid2'] == 0) {
            return;
        }
        if ($uss [ulevel] == 3) {
            $b2 = 100;
            edit_sql ( "update `member` set b2=b2+$b2 where id=" . $uss ['id'] . "" );
            $this->bonus_laiyuan ( $uss ['id'], $uss ['nickname'], $id, $nickname, 2, $b2, "见点分红" );
            $this->b3bonus ( $uss ['id'], $uss ['nickname'], $b2 );
            $this->b0bonus ( $uid, $nickname );
            return $uss ['id'];
        } elseif ($uss [ulevel] == 4) {
            return $uss ['id'];
        } else {
            return $this->jinsuo22 ( $uss ['id'], $rs ['id'], $rs ['nickname'] );
        }
    }


    // 购买养生用品
    function yfh($id, $nickname, $dpid, $lsk) {
        $_ulevel_cl = new ulevel_class ();
        $us = getMemberbyID ( $dpid );
        $me = getMemberbyID ( $id );
        $_iul = $_ulevel_cl->getulevelbyulevel ( $us ['ulevel'] );
        $_iul = $_ulevel_cl->getulevelbyulevel ( $me ['ulevel'] );
// 		if ($us ['ulevel'] >= 2) {
        $b4 = $lsk * (25-$_iul ['yl4']) / 100;
        if ($b4 > 0) {
            edit_sql ( "update `member` set b4=b4+$b4 where id=" . $us ['id'] . "" );
            $this->bonus_laiyuan ( $us ['bdid'], $us ['bdname'], $id, $nickname, 4, $b4, "购物返利" );
        }
        $b4 = $lsk * $_iul ['yl4'] / 100;
        $rs = getMemberbyID ( $me ['bdid'] );
        if ($b4 > 0) {
            edit_sql ( "update `member` set b4=b4+$b4 where id=" . $me ['bdid'] . "" );
            $this->bonus_laiyuan ( $me ['bdid'], $me ['bdname'], $id, $nickname, 4, $b4, "购物返利" );
        }
        $this->b0bonus ( $id, $nickname );
// 		}
    }
    // 购保健品
    function bfh($id, $nickname, $dpid, $lsk) {
        $_ulevel_cl = new ulevel_class ();
        $us = getMemberbyID ( $dpid );
        $_iul = $_ulevel_cl->getulevelbyulevel ( $us ['ulevel'] );
        $b4 = $lsk * $_iul ['yl5'] / 100;
        if ($b4 > 0) {
            edit_sql ( "update `member` set b4=b4+$b4  where id=" . $us ['id'] . "" );
            $this->bonus_laiyuan ( $us ['bdid'], $us ['bdname'], $id, $nickname, 4, $b4, "购物返利" );
        }
        $this->b0bonus ( $id, $nickname );
    }
    // 购日用品
    function riyong($id, $nickname, $dpid, $bdid, $lsk) {
        $_ulevel_cl = new ulevel_class ();
        $us = getMemberbyID ( $dpid );
        $me = getMemberbyID ( $id );
        $iul = $_ulevel_cl->getulevelbyulevel ( $us ['ulevel'] );
        $_iul = $_ulevel_cl->getulevelbyulevel ( $me ['ulevel'] );
// 		if ($us ['ulevel'] >= 2) {
        $b4 = $lsk *(10- $iul ['yl6']) / 100;
        if ($b4 > 0) {
            edit_sql ( "update `member` set b4=b4+$b4 where id=" . $us ['id'] . "" );
            $this->bonus_laiyuan ( $us ['bdid'], $us ['bdname'], $id, $nickname, 4, $b4, "购物返利" );
        }
        $b4 = $lsk * $iul ['yl6'] / 100;
        if ($b4 > 0) {
            edit_sql ( "update `member` set b4=b4+$b4 where id=" . $me ['bdid'] . "" );
            $this->bonus_laiyuan ( $me ['bdid'], $me ['bdname'], $id, $nickname, 4, $b4, "购物返利" );
        }
// 		}
        $this->b0bonus ( $id, $nickname );
    }
    function zjulevel() {
        $sql = "select id,recount,ulevel from memeber where recount>0";
        $query = mysql_query ( $sql );
        while ( $row = mysql_fetch_assoc ( $query ) ) {
            if ($row ['ulevel'] == 2) {
                if ($row ['recount'] == 1) {
                    edit_sql ( "update `member` set zjulevel=1  where id=" . $row ['id'] . "" );
                } elseif ($row ['recount'] == 2) {
                    edit_sql ( "update `member` set zjulevel=2  where id=" . $row ['id'] . "" );
                }
            } else {
                $sql1 = "select id,recount,ulevel from memeber where reid=" . $row ['id'] . "";
                $query1 = mysql_query ( $sql1 );
                while ( $us = mysql_fetch_assoc ( $query1 ) ) {
                    if ($us ['ulevel'] >= 3) {
                        if ($row ['recount'] == 1) {
                            edit_sql ( "update `member` set zjulevel=1  where id=" . $row ['id'] . "" );
                        } elseif ($row ['recount'] == 2) {
                            edit_sql ( "update `member` set zjulevel=2  where id=" . $row ['id'] . "" );
                        }
                    }
                }
            }
        }
        $this->zjulevel1 ();
    }

    // 职级会员
    function zjulevel1() {
        $sql = "SELECT id FROM `member` where recount>0";
        if ($query = mysql_query ( $sql )) {
            while ( $row = mysql_fetch_array ( $query ) ) {
                $sql1 = "select ulevel from member where repath like '%" . $row ['id'] . "%' and zjulevel=1  ";
                $query1 = mysql_query ( $sql1 );
                $num1 = mysql_num_rows ( $query1 );
                if ($num1 == 1) {
                    edit_sql ( "update `member` set  zjulevel=3 where id=" . $row ['id'] . "" );
                } elseif ($num1 == 2) {
                    // 先进店
                    edit_sql ( "update `member` set  zjulevel=4 where id=" . $row ['id'] . "" );
                }
            }
        }
    }
    function gu() {
        $sql = "SELECT id FROM `member` where recount>0";
        if ($query = mysql_query ( $sql )) {
            while ( $row = mysql_fetch_array ( $query ) ) {
                $sql1 = "select ulevel from member where repath like '%" . $row ['id'] . "%' and zjulevel=4  ";
                $query1 = mysql_query ( $sql1 );
                while ( $row1 = mysql_fetch_assoc ( $query1 ) ) {
                    if ($row1 ['ulevel'] == 2) {
                        $gu = 1;
                    } elseif ($row1 ['ulevel'] == 3) {
                        $gu = 11;
                    } elseif ($row1 ['ulevel'] == 4) {
                        $gu = 33;
                    }
                    if ($row ['plevel'] >= 3) {
                        edit_sql ( "update `member` set  gu=gu+$gu where id=" . $row ['id'] . "" );
                        edit_sql ( "update `member` set  gu=gu+$gu where id=1" );
                    }
                }
            }
        }
    }
    // 加权分红
    function fh() {
        $us = getMemberbyID ( 1 );
        $lsk = $us ['aixinjin'] / $us ['gu'];
        $sql = "SELECT id,gu FROM `member` where gu>0";
        if ($query = mysql_query ( $sql )) {
            while ( $row = mysql_fetch_assoc ( $query ) ) {
                $b5 = 0.7 * $lsk * $row [gu];
                if ($b5 > 0) {
                    edit_sql ( "update `member` set  b5=b5+$b5,gu=0 where id=" . $row ['id'] . "" );
                    edit_sql ( "update `member` set  aixinjin=0,gu=0 where id=1" );
                }
            }
        }
    }

    /*
     * 查询累计金额 $_jx=积分类型b0,b1,b2…… $_uid=查询编号 $_lx=查询类型0总计,1月,2日,3周
     */
    function ljbonus($_jx, $_uid, $_lx) {
        $y = date ( "Y", strtotime ( now () ) );
        $m = date ( "m", strtotime ( now () ) );
        $d = date ( "d", strtotime ( now () ) );
        $sql = "SELECT sum(" . $_jx . ") from `bonus` where uid=" . $_uid . "";
        if ($_lx == 1) {
            $sql = $sql . " and year(bdate)=" . $y . " and month(bdate)=" . $m . "";
        } else if ($_lx == 2) {
            $sql = $sql . " and year(bdate)=" . $y . " and month(bdate)=" . $m . " and day(bdate)=" . $d . "";
        } else if ($_lx == 3) {
            $sql = $sql . " and month(bdate) = month(curdate()) and week(bdate,1) = week(curdate(),1)";
        }

        if ($query = mysql_query ( $sql )) {
            while ( $row = mysql_fetch_array ( $query ) ) {
                $fanhui = $row [0];
            }
        } else {
            $fanhui = 0;
        }

        return $fanhui;
    }


    function b0bonus(){
        $_ulevel_cl=new ulevel_class();
        $system_cl=new system_class();
        $_system=$system_cl->system_information(1);
        $lj=0;
        $sql="SELECT * FROM `member` WHERE b1>0 or b2>0 or b3>0 or b4>0 or b5>0 or b6>0 or b7>0 or b8>0 or b9>0 or b10>0 or b11>0 or b12>0";
        if ($query=mysql_query($sql)){
            if(mysql_num_rows($query)>0){
                $wlf=$_system['wlf'];//复投
                $ls=$_system['sl'];//手续费
                $jmf2=$_system['jmf2'];//扣提现手续费
                $aixinjijin=$_system['aixinjijin'];//扣爱心基金
                $chongfuxiaofei=$_system['chongfuxiaofei'];//重复消费
                $lx=1; //产生数据条数,0产生N条,1每日产生1条
                $did=$this->bonustime_insert($lx);
                while ($row=mysql_fetch_array($query)){
                    $_iul=$_ulevel_cl->getulevelbyulevel($row['ulevel']);
                    $member_update=NULL;
                    $b1=$row['b1'];
                    $b2=$row['b2'];
                    $b3=$row['b3'];
                    $b4=$row['b4'];
                    $b5=$row['b5'];
                    $b6=$row['b6'];
                    $b7=$row['b7'];
                    $b8=$row['b8'];
                    $b9=$row['b9'];
                    $b10=$row['b10'];
                    $b0=$b1+$b2+$b3+$b6;
                    if($b0>0){
                          if($aixinjijin>0){
                       //     $b8=$b0/100*$ls;//手续费
                            $b10=$b0/100*$aixinjijin;//重复消费
                            $b0=$b0-$b10;
                            edit_sql("update `member` set sgb=sgb+{$b10} where id = ".$row['id']);
                      //      $beizhu2=$ls."%扣手续费";
                            $beizhu4=$aixinjijin."%扣爱心基金";
                      //      $this->bonus_laiyuan($row['id'],$row['nickname'],$row['id'],$row['nickname'],8,-$b8,$beizhu2);
                            $this->bonus_laiyuan($row['id'],$row['nickname'],$row['id'],$row['nickname'],10,-$b10,$beizhu4);
                        }
                    }
                    $member_update['b0']=0;
                    $member_update['b1']=0;
                    $member_update['b2']=0;
                    $member_update['b3']=0;
                    $member_update['b4']=0;
                    $member_update['b5']=0;
                    $member_update['b6']=0;
                    $member_update['b7']=0;
                    $member_update['b8']=0;
                    $member_update['b9']=0;
                    $member_update['b10']=0;
                    $member_update['b11']=0;
                    $member_update['b12']=0;
                    $member_update['mey']=$row['mey']+$b0;
                    $member_update['maxmey']=$row['maxmey']+$b0;

                    edit_update_cl('member',$member_update,$row['id']);
                    $bonus_update['did']=$did;
                    $bonus_update['uid']=$row['id'];
                    $bonus_update['b0']=$b0;
                    $bonus_update['b1']=$b1;
                    $bonus_update['b2']=$b2;
                    $bonus_update['b3']=$b3;
                    $bonus_update['b4']=$b4;
                    $bonus_update['b5']=$b5;
                    $bonus_update['b6']=$b6;
                    $bonus_update['b7']=$b7;
                    $bonus_update['b8']=$b8;
                    $bonus_update['b9']=$b9;
                    $bonus_update['b10']=$b10;
                    $lj=$lj+$b0;
                    //if($b0>0 || $b7>0 || $b8>0){
                    $this->bonus_insert($lx,$bonus_update);
                    //}
                }
            }
        }
        $_systemyeji=new system_class();
        $_systemyeji->yejitongji(0,0,0,$lj,0,0,0);
    }

    function b0bonusjingtai(){
        $_ulevel_cl=new ulevel_class();
        $system_cl=new system_class();
        $_system=$system_cl->system_information(1);
        $lj=0;
        $sql="SELECT * FROM `member` WHERE b1>0 or b2>0 or b3>0 or b4>0 or b5>0 or b6>0 or b7>0 or b8>0 or b9>0 or b10>0 or b11>0 or b12>0";
        if ($query=mysql_query($sql)){
            if(mysql_num_rows($query)>0){
                $wlf=$_system['wlf'];//复投
                $ls=$_system['sl'];//手续费
                $jmf2=$_system['jmf2'];//扣提现手续费
                $aixinjijin=$_system['aixinjijin'];//扣除车房基金
                $chongfuxiaofei=$_system['chongfuxiaofei'];//重复消费
                $lx=1; //产生数据条数,0产生N条,1每日产生1条
                $did=$this->bonustime_insert($lx);
                while ($row=mysql_fetch_array($query)){
                    $_iul=$_ulevel_cl->getulevelbyulevel($row['ulevel']);
                    $member_update=NULL;
                    $b1=$row['b1'];
                    $b2=$row['b2'];
                    $b3=$row['b3'];
                    $b4=$row['b4'];
                    $b5=$row['b5'];
                    $b6=$row['b6'];
                    $b7=$row['b7'];
                    $b8=$row['b8'];
                    $b9=$row['b9'];
                    $b10=$row['b10'];
                    $b0=$b2+$b3+$b4+$b5+$b6;
                    if($b0>0){
                          if($chongfuxiaofei>0){
                       //     $b8=$b0/100*$ls;//手续费
                            $b10=$b0/100*$chongfuxiaofei;//重复消费
                            $b0=$b0-$b10;
                            edit_sql("update `member` set cfxf=cfxf+{$b10} where id = ".$row['id']);
                      //      $beizhu2=$ls."%扣手续费";
                            $beizhu4=$chongfuxiaofei."%扣重复消费";
                      //      $this->bonus_laiyuan($row['id'],$row['nickname'],$row['id'],$row['nickname'],8,-$b8,$beizhu2);
                            $this->bonus_laiyuan($row['id'],$row['nickname'],$row['id'],$row['nickname'],10,-$b10,$beizhu4);
                        }
                    }
                    $member_update['b0']=0;
                    $member_update['b1']=0;
                    $member_update['b2']=0;
                    $member_update['b3']=0;
                    $member_update['b4']=0;
                    $member_update['b5']=0;
                    $member_update['b6']=0;
                    $member_update['b7']=0;
                    $member_update['b8']=0;
                    $member_update['b9']=0;
                    $member_update['b10']=0;
                    $member_update['b11']=0;
                    $member_update['b12']=0;
                    $member_update['mey']=$row['mey']+$b0;
                    $member_update['maxmey']=$row['maxmey']+$b0;

                    edit_update_cl('member',$member_update,$row['id']);
                    $bonus_update['did']=$did;
                    $bonus_update['uid']=$row['id'];
                    $bonus_update['b0']=$b0;
                    $bonus_update['b1']=$b1;
                    $bonus_update['b2']=$b2;
                    $bonus_update['b3']=$b3;
                    $bonus_update['b4']=$b4;
                    $bonus_update['b5']=$b5;
                    $bonus_update['b6']=$b6;
                    $bonus_update['b7']=$b7;
                    $bonus_update['b8']=$b8;
                    $bonus_update['b9']=$b9;
                    $bonus_update['b10']=$b10;
                    $lj=$lj+$b0;
                    //if($b0>0 || $b7>0 || $b8>0){
                    $this->bonus_insert($lx,$bonus_update);
                    //}
                }
            }
        }
    }
    function b0bonus0(){
        $_ulevel_cl=new ulevel_class();
        $system_cl=new system_class();
        $_system=$system_cl->system_information(1);
        $lj=0;
        $sql="SELECT * FROM `member` WHERE b1>0 or b2>0 or b3>0 or b4>0 or b5>0 or b6>0 or b7>0 or b8>0 or b9>0 or b10>0 or b11>0 or b12>0";
        if ($query=mysql_query($sql)){
            if(mysql_num_rows($query)>0){
                $lx=1; //产生数据条数,0产生N条,1每日产生1条
                $did=$this->bonustime_insert($lx);
                while ($row=mysql_fetch_array($query)){
                    $_iul=$_ulevel_cl->getulevelbyulevel($row['ulevel']);
                    $member_update=NULL;
                    $b1=$row['b1'];
                    $b2=$row['b2'];
                    $b3=$row['b3'];
                    $b4=$row['b4'];
                    $b5=$row['b5'];
                    $b6=$row['b6'];
                    $b7=$row['b7'];
                    $b8=$row['b8'];
                    $b9=$row['b9'];
                    $b10=$row['b10'];
                    $b0=$b1+$b2+$b3+$b4+$b5+$b6;
                    if($b0>0){
                            $wlf=0.1;
                            $ls=0.2;
                            $b7=$b0/100*$wlf;//复投
                            $b8=$b0/100*$ls;//公司收入
                            $b0=$b0-$b8-$b7;
                            edit_sql("update `member` set wlf=wlf+{$b7} where id = ".$row['id']);
                            $beizhu1="10%复投";
                            $beizhu2="20%扣公司收入";
                            $this->bonus_laiyuan($row['id'],$row['nickname'],$row['id'],$row['nickname'],7,-$b7,$beizhu1);
                            $this->bonus_laiyuan($row['id'],$row['nickname'],$row['id'],$row['nickname'],8,-$b8,$beizhu2);

                    }
                    $member_update['b0']=0;
                    $member_update['b1']=0;
                    $member_update['b2']=0;
                    $member_update['b3']=0;
                    $member_update['b4']=0;
                    $member_update['b5']=0;
                    $member_update['b6']=0;
                    $member_update['b7']=0;
                    $member_update['b8']=0;
                    $member_update['b9']=0;
                    $member_update['b10']=0;
                    $member_update['b11']=0;
                    $member_update['b12']=0;
                    $member_update['mey']=$row['mey']+$b0;
                    $member_update['maxmey']=$row['maxmey']+$b0;

                    edit_update_cl('member',$member_update,$row['id']);
                    $bonus_update['did']=$did;
                    $bonus_update['uid']=$row['id'];
                    $bonus_update['b0']=$b0;
                    $bonus_update['b1']=$b1;
                    $bonus_update['b2']=$b2;
                    $bonus_update['b3']=$b3;
                    $bonus_update['b4']=$b4;
                    $bonus_update['b5']=$b5;
                    $bonus_update['b6']=$b6;
                    $bonus_update['b7']=$b7;
                    $bonus_update['b8']=$b8;
                    $bonus_update['b9']=$b9;
                    $bonus_update['b10']=$b10;
                    $lj=$lj+$b0;
                    //if($b0>0 || $b7>0 || $b8>0){
                    $this->bonus_insert($lx,$bonus_update);
                    //}
                }
            }
        }
        $_systemyeji=new system_class();
        $_systemyeji->yejitongji(0,0,0,$lj,0,0,0);
    }

    /*
     * @lx 0产生多条数据，1每天产生1条
     */
    function bonustime_insert($lx) {
        $y = date ( "Y" );
        $m = date ( "m" );
        $d = date ( "d" );
        if ($lx == 1) {
            $sql = "SELECT * FROM `bonustime` WHERE year(jsdate)=" . $y . " and month(jsdate)=" . $m . " and day(jsdate)=" . $d . "";
            $query = mysql_query ( $sql );
            if ($_bonustime = mysql_fetch_array ( $query )) {
                $did = $_bonustime ['id'];
            } else {
                $sql1 = "INSERT INTO bonustime(jsdate,jslx) VALUES('" . now () . "',1)";
                $reult = mysql_query ( $sql1 );
                $did = mysql_insert_id ();
            }
        } else if ($lx == 0) {
            $sql1 = "INSERT INTO bonustime(jsdate,jslx) VALUES('" . now () . "',1)";
            $reult = mysql_query ( $sql1 );
            $did = mysql_insert_id ();
        }
        return $did;
    }

    /*
     * @lx 0产生多条数据，1每天产生1条,必须与bonustime的lx同步
     */
    function bonus_insert($lx, $_bonus) {
        $y = date ( "Y" );
        $m = date ( "m" );
        $d = date ( "d" );
        if ($lx == 1) {
            $sql = "SELECT * FROM `bonus` WHERE year(bdate)=" . $y . " and month(bdate)=" . $m . " and day(bdate)=" . $d . " and uid=" . $_bonus ['uid'] . "";
            $query = mysql_query ( $sql );
            if ($bonus = mysql_fetch_array ( $query )) {
                $bonus_update = NULL;
                $bonus_update ['b0'] = $bonus ['b0'] + $_bonus ['b0'];
                $bonus_update ['b1'] = $bonus ['b1'] + $_bonus ['b1'];
                $bonus_update ['b2'] = $bonus ['b2'] + $_bonus ['b2'];
                $bonus_update ['b3'] = $bonus ['b3'] + $_bonus ['b3'];
                $bonus_update ['b4'] = $bonus ['b4'] + $_bonus ['b4'];
                $bonus_update ['b5'] = $bonus ['b5'] + $_bonus ['b5'];
                $bonus_update ['b6'] = $bonus ['b6'] + $_bonus ['b6'];
                $bonus_update ['b7'] = $bonus ['b7'] + $_bonus ['b7'];
                $bonus_update ['b8'] = $bonus ['b8'] + $_bonus ['b8'];
                $bonus_update ['b9'] = $bonus ['b9'] + $_bonus ['b9'];
                $bonus_update ['b10'] = $bonus ['b10'] + $_bonus ['b10'];
                $bonus_update ['b11'] = $bonus ['b11'] + $_bonus ['b11'];
                $bonus_update ['b12'] = $bonus ['b12'] + $_bonus ['b12'];
                $bonus_update ['b13'] = $bonus ['b13'] + $_bonus ['b13'];
                edit_update_cl ( 'bonus', $bonus_update, $bonus ['id'] );
            } else {
                $bonus_update = NULL;
                $bonus_update ['bdate'] = now ();
                $bonus_update ['did'] = $_bonus ['did'];
                $bonus_update ['uid'] = $_bonus ['uid'];
                $bonus_update ['b0'] = $_bonus ['b0'];
                $bonus_update ['b1'] = $_bonus ['b1'];
                $bonus_update ['b2'] = $_bonus ['b2'];
                $bonus_update ['b3'] = $_bonus ['b3'];
                $bonus_update ['b4'] = $_bonus ['b4'];
                $bonus_update ['b5'] = $_bonus ['b5'];
                $bonus_update ['b6'] = $_bonus ['b6'];
                $bonus_update ['b7'] = $_bonus ['b7'];
                $bonus_update ['b8'] = $_bonus ['b8'];
                $bonus_update ['b9'] = $_bonus ['b9'];
                $bonus_update ['b10'] = $_bonus ['b10'];
                $bonus_update ['b11'] = $_bonus ['b11'];
                $bonus_update ['b12'] = $_bonus ['b12'];
                $bonus_update ['b13'] = $_bonus ['b13'];
                add_insert_cl ( 'bonus', $bonus_update );
            }
        } else if ($lx == 0) {
            $bonus_update = NULL;
            $bonus_update ['bdate'] = now ();
            $bonus_update ['did'] = $_bonus ['did'];
            $bonus_update ['uid'] = $_bonus ['uid'];
            $bonus_update ['b0'] = $_bonus ['b0'];
            $bonus_update ['b1'] = $_bonus ['b1'];
            $bonus_update ['b2'] = $_bonus ['b2'];
            $bonus_update ['b3'] = $_bonus ['b3'];
            $bonus_update ['b4'] = $_bonus ['b4'];
            $bonus_update ['b5'] = $_bonus ['b5'];
            $bonus_update ['b6'] = $_bonus ['b6'];
            $bonus_update ['b7'] = $_bonus ['b7'];
            $bonus_update ['b8'] = $_bonus ['b8'];
            $bonus_update ['b9'] = $_bonus ['b9'];
            $bonus_update ['b10'] = $_bonus ['b10'];
            $bonus_update ['b11'] = $_bonus ['b11'];
            $bonus_update ['b12'] = $_bonus ['b12'];
            add_insert_cl ( 'bonus', $bonus_update );
        }
    }

    // 写入积分来源
    function bonus_laiyuan($uid, $nickname, $yid, $ynickname, $lx, $jine, $beizhu) {
        $bonuslaiyuan = NULL;
        $bonuslaiyuan ['uid'] = $uid;
        $bonuslaiyuan ['nickname'] = $nickname;
        $bonuslaiyuan ['yid'] = $yid;
        $bonuslaiyuan ['ynickname'] = $ynickname;
        $bonuslaiyuan ['lx'] = $lx;
        $bonuslaiyuan ['jine'] = $jine;
        $bonuslaiyuan ['bdate'] = now ();
        $bonuslaiyuan ['beizhu'] = $beizhu;
        add_insert_cl ( 'bonuslaiyuan', $bonuslaiyuan );
    }
}
?>